package com.hky.front_end_monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hky.front_end_monitor.dto.UserAuDTO;
import com.hky.front_end_monitor.entity.SysUser;
import com.hky.front_end_monitor.service.SysUserService;
import com.hky.front_end_monitor.mapper.SysUserMapper;
import com.hky.front_end_monitor.utils.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author hello
 * @description 针对表【sys_user】的数据库操作Service实现
 * @createDate 2022-08-02 21:47:59
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
        implements SysUserService {
    @Resource
    private SysUserMapper sysUserMapper;
    @Override
    public boolean isLegitimateUser(Map map) {
        String userId = StringUtils.caseToString(map.get("userId"));
        String deviceId = StringUtils.caseToString(map.get("deviceId"));
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getUserId, userId)
                .eq(SysUser::getDeviceId, deviceId);
        return sysUserMapper.exists(queryWrapper);
    }
    public boolean isLegitimateUser(UserAuDTO userAuDTO) {
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getUserId, userAuDTO.getUserId())
                .eq(SysUser::getDeviceId, userAuDTO.getDeviceId());
        return sysUserMapper.exists(queryWrapper);
    }
}




